package com.suzus.aiService.controller;

import com.suzus.aiService.common.result.Result;
import com.suzus.aiService.pojo.entity.Message;
import com.suzus.aiService.service.AskService;
import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
public class ChatController {

    private final OllamaChatClient chatClient;

    @Autowired
    public AskService askService;

    @Autowired
    public ChatController(OllamaChatClient chatClient) {
        this.chatClient = chatClient;
    }

    //这个是症状查询的接口，传入一个String类型字符串并返回结果
    @PostMapping("/ai/askOllama")
    public Result<Message> generate(@RequestBody Message message) {
        String question = message + ", 请给我一些建议";
        String result = chatClient.call(question);
        return Result.success(Message.builder().message(result).build());
    }

    //不调用本地模型 而是调用百度模型
    @PostMapping("/ai/ask")
    public Result<Message> generateQianFan(@RequestBody Message message) {
        String Question = message + ", 请给我一些建议";
        Message result = askService.getAdviceBySymptom(Question);
        return Result.success(result);

    }


}
